<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>sem_post</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_008_315">&nbsp;</a>NAME</h4><blockquote>
sem_post - unlock a semaphore
(<b>REALTIME</b>)
</blockquote><h4><a name = "tag_000_008_316">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="semaphore.h.html">semaphore.h</a>&gt;

int sem_post(sem_t *<i>sem</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_008_317">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>sem_post()</i>
function unlocks the semaphore
referenced by
<i>sem</i>
by performing a semaphore unlock operation
on that semaphore.
<p>
If the semaphore value resulting from this operation is positive,
then no threads 
were blocked waiting for the semaphore to become unlocked;
the semaphore value is simply incremented.
<p>
If the value of the semaphore resulting from this operation is zero,
then one of the threads 
blocked waiting for the semaphore
will be allowed to return successfully from its call to
<i><a href="sem_wait.html">sem_wait()</a></i>.
If the symbol _POSIX_PRIORITY_SCHEDULING
is defined, the thread 
to be unblocked will be chosen in a
manner appropriate to the scheduling policies and parameters in
effect for the blocked threads.
In the case of the schedulers SCHED_FIFO and SCHED_RR,
the highest priority waiting thread 
will be unblocked, and
if there is more than one highest priority thread 
blocked
waiting for the semaphore,
then the highest priority thread
that has been waiting the longest will be unblocked.
If the symbol _POSIX_PRIORITY_SCHEDULING is not defined,
the choice of a thread 
to unblock is unspecified.
<p>
The
<i>sem_post()</i>
interface is reentrant with respect to signals and
may be invoked from a signal-catching function.
</blockquote><h4><a name = "tag_000_008_318">&nbsp;</a>RETURN VALUE</h4><blockquote>
If successful, the
<i>sem_post()</i>
function returns zero;
otherwise the function returns -1 and sets
<i>errno</i>
to indicate the error.
</blockquote><h4><a name = "tag_000_008_319">&nbsp;</a>ERRORS</h4><blockquote>
The 
<i>sem_post()</i>
function will fail if:
<dl compact>

<dt>[EINVAL]<dd>
The
<i>sem</i>
does not refer to a valid semaphore.

<dt>[ENOSYS]<dd>
The function
<i>sem_post()</i>
is not supported by this implementation.

</dl>
</blockquote><h4><a name = "tag_000_008_320">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_008_321">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_008_322">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_008_323">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="semctl.html">semctl()</a></i>,
<i><a href="semget.html">semget()</a></i>,
<i><a href="semop.html">semop()</a></i>,
<i><a href="sem_trywait.html">sem_trywait()</a></i>,
<i><a href="sem_wait.html">sem_wait()</a></i>,
<i><a href="semaphore.h.html">&lt;semaphore.h&gt;</a></i>.
</blockquote><h4>DERIVATION</h4><blockquote>
Derived from the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995)
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>

